


//初始化运动
function initPedometer(){
	
	
	var name = navigator.platform;
	var deviceBindingState=indexPedometerData.deviceBindingState;
	document.getElementById("pedometer_upload").style.display="none";
	
	if (name.substring(0, 6) == "iPhone" || name.substring(0, 4) == "iPod"
			|| name.substring(0, 4) == "iPad") {
		init_piphone_onclick();
	} else {
		init_phtml_onclick();
	}
	
	if(deviceBindingState!=1){
		if(indexPedometerData.stepDay==0){
			document.getElementById("pedometer_circle_havedate").style.display="none";
			document.getElementById("pedometer_circle_havetext").style.display="none";
			document.getElementById("pedometer_circle_text").style.display="none";
			document.getElementById("pedometer_circle_step").style.display="none";
			document.getElementById("pedometer_today").style.display="none";
			document.getElementById("pedometer_circle_notext").style.display="block";
		}else{
			document.getElementById("pedometer_circle_havedate_value").innerHTML=indexPedometerData.dateDay;
			document.getElementById("pedometer_circle_havedate").style.display="block";
			document.getElementById("pedometer_circle_havetext").style.display="block";
			document.getElementById("pedometer_circle_step").innerHTML=indexPedometerData.stepDay;
			document.getElementById("pedometer_today_per").innerHTML=indexPedometerData.stepPre;
		}
		if(indexPedometerData.weekPre=="0%"){
			document.getElementById("pedometer_week").style.display="none";
		}else{
			document.getElementById("pedometer_week_per").innerHTML=indexPedometerData.weekPre;
		}
		testDrawTree2();
	}else{
		document.getElementById("pedometer").style.display="none";
		document.getElementById("pedometer_no").style.display="block";
	}
	
	
//	document.getElementById("pedometer_today").innerHTML="正在更新数据";
//	document.getElementById("pedometer_today").style.display="block";
//	document.getElementById("pedometer_today").style.marginTop="1px";
//	document.getElementById("pedometer_point").style.display="block";
	
}
//点击事件监听
function init_piphone_onclick(){
	var setting=document.getElementById("mod-pedometer");
	setting.addEventListener("click", clickImg, false);
}
function init_phtml_onclick(){
	var setting=document.getElementById("mod-pedometer");
	setting.addEventListener("click", clickImg, false);
}
//点击图片跳转	
function clickImg(){
	parent.document.title = "运动";
	var openId=parent.document.getElementById("openId").value;
	var memberId = parent.document.getElementById("memberId").value;
	if(indexPedometerData.deviceBindingState==1){
		window.location.href=ctx+"/v3/pedometer/buy.html";
		parent.selectMenu(0);
	}else if(indexPedometerData.deviceBindingState==2){
		parent.window.location.href="/page/sport?openId="+openId+"&memberId="+memberId+"&deviceBindingState=2";
	}else if(indexPedometerData.deviceBindingState==4){
		parent.window.location.href="/page/sport?openId="+openId+"&memberId="+memberId+"&deviceBindingState=4";
	}else{
		parent.window.location.href="/page/sport?openId="+openId+"&memberId="+memberId;
	}
	
}
var uploadTime=null;
function upload(type){
	if(type==0){
		document.getElementById("pedometer_upload").style.display="block";
	}else{
		var pedometer_upload = document.getElementById("pedometer_upload");
		if(pedometer_upload.style.display=="block"){
			pedometer_upload.style.display="none";
		}else{
			pedometer_upload.style.display="block";
			setTimeout(clearUpload, 3000);
		}
	}
}

function clearUpload(){
	document.getElementById("pedometer_upload").style.display="none";
	ajaxLoadIndexPedometerData();
}

var start=1.5;
var end=1.5;
function drawUpload(){
	var canvas = document.getElementById("pedometer_circle_canvas");
	if (canvas == null) {
		return false;
	}
	var context = canvas.getContext("2d");
	var cWidth = canvas.offsetWidth;
	var width = cWidth * 2;
	var height = cWidth * 2;
	canvas.width = width;
	canvas.height = height;
	context.clearRect(0, 0, canvas.width, canvas.height);
	
	if(ii>=3){
		ii=1;
	}else{
		ii+=1;
	}
	
	var dian="";
	for (var i = 0; i < ii; i++) {
		dian+=".";
	}
	
	context.beginPath();
	context.fillStyle = "#7e7d7f";
	context.font = "30px Helvetica";
	context.fillText("数据",  45, 65 );
	context.fillText("上传中"+dian,  20, 95 );
	context.closePath();
	
}

var ii=1;


var treeDate2 = {
		// "hLine":5000,//有目标线
		"hLine":11220,//无目标线
		"nullTips":'暂无数据',//是否有数据
		"xLables":['一','二','三','四','五','六','七'],//底部文字
		"yValues":[2000,1500,8000,10000,10000,7000,5000]//树状图的长度
		//"yValues":[]//无数据
	};
//测试
function testDrawTree2(){
	var canvas = document.getElementById("mod-pedometer-canvas");
	var treeTW = document.getElementById("pedometer_right").offsetWidth;
	var isNoValues=true;
	for(var i=0;i<indexPedometerData.yValues.length;i++){
		if(indexPedometerData.yValues[i]>0){
			isNoValues=false;
        	break;
		}
	}
    if(isNoValues){
    	indexPedometerData.yValues=[];
    }
	
	console.log(treeTW)
//	treeTW = 188;
	drawTreeToHome(treeTW * 2,75 * 2,canvas,"#f7882d","#f7882d","gray",indexPedometerData);
}
